﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Character_Generator
{
    public partial class Created_Characters : Form
    {
        //Necessary to communicate with the parent form
        private frmGenerator m_parent;

        //Form Initilization Event
        //Initialize a variable called frm1 that uses the
        //parent form.
        public Created_Characters(frmGenerator frm1)
        {
            InitializeComponent();
            m_parent = frm1;
        }

        //Initialize arrays to store data from the Data File.
        string[] m_strCharacterName = new string[8];
        byte[] m_bytCharacterClass = new byte[8];
        byte[] m_bytCharacterGender = new byte[8];
        byte[] m_bytCharacterStrength = new byte[8];
        byte[] m_bytCharacterDexterity = new byte[8];
        byte[] m_bytCharacterAgility = new byte[8];
        byte[] m_bytCharacterConstitution = new byte[8];
        byte[] m_bytCharacterAcumen = new byte[8];
        byte[] m_bytCharacterFaith = new byte[8];
        byte[] m_bytCharacterWillpower = new byte[8];
        byte[] m_bytCharacterCharisma = new byte[8];
        string[] m_strCharacterPrimaryTrade = new string[8];
        string[] m_strCharacterSecondaryTrade = new string[8];

        //Initialize variables that tell the program which data to use
        //when loading the character view panel.
        byte bytCharacterCounter = 0;
        byte bytCharacterName = 0;

        //Load Event of the form
        private void Created_Characters_Load(object sender, EventArgs e)
        {

            //Make the Character Selection Panel visible and Character
            //View Panel invisible.
            pnlCharacters.Visible = true;
            pnlCharacters2.Visible = false;

            //Initialize the variables and arrays used in obtaining the
            //data from the Data File.
            string line;
            string[] field;
            char delimiter = ',';
            byte bytCounter = 0;

            //Open the Data File.
            StreamReader csr = new StreamReader(@"C:\HOD Character Generator.txt");

            //Take the data from the Data File and place it into arrays.
            while ((line = csr.ReadLine()) != null)
            {
                field = line.Split(delimiter);
                m_strCharacterName[bytCounter] = field[0];
                m_bytCharacterClass[bytCounter] = Convert.ToByte(field[1]);
                m_bytCharacterGender[bytCounter] = Convert.ToByte(field[2]);
                m_bytCharacterStrength[bytCounter] = Convert.ToByte(field[3]);
                m_bytCharacterDexterity[bytCounter] = Convert.ToByte(field[4]);
                m_bytCharacterAgility[bytCounter] = Convert.ToByte(field[5]);
                m_bytCharacterConstitution[bytCounter] = Convert.ToByte(field[6]);
                m_bytCharacterAcumen[bytCounter] = Convert.ToByte(field[7]);
                m_bytCharacterFaith[bytCounter] = Convert.ToByte(field[8]);
                m_bytCharacterWillpower[bytCounter] = Convert.ToByte(field[9]);
                m_bytCharacterCharisma[bytCounter] = Convert.ToByte(field[10]);
                m_strCharacterPrimaryTrade[bytCounter] = field[11];
                m_strCharacterSecondaryTrade[bytCounter] = field[12];
                bytCounter++;
                bytCharacterCounter++;
            }

            //Close the Data File.
            csr.Close();

            //Reset the Character Selection form to the first character in
            //the Data File.
            lblName.Text = m_strCharacterName[bytCharacterName];
        }

        //Character Scroll Right Button Click Event
        private void btnCharacterForward_Click(object sender, EventArgs e)
        {
            //Reset to the first character in the Data File once the
            //last character is reached.
            if (bytCharacterName < (bytCharacterCounter - 1))
            {
                bytCharacterName++;
                lblName.Text = m_strCharacterName[bytCharacterName];
            }
                
            //Scroll through the list of characters from the Data
            //File and Display their names.
            else
            {
                bytCharacterName = 0;
                lblName.Text = m_strCharacterName[bytCharacterName];
            }

        }

        //Character Selection Scroll Leftwards Button Click Event
        private void btnCharacterBack_Click(object sender, EventArgs e)
        {

            //Reset the character list back to the first character once
            //it reaches the end.
            if (bytCharacterName > 0)
            {
                bytCharacterName--;
                lblName.Text = m_strCharacterName[bytCharacterName];
            }

            //Scroll through the character list and display the name
            //of the character.
            else
            {
                bytCharacterName = Convert.ToByte(bytCharacterCounter - 1);
                lblName.Text = m_strCharacterName[bytCharacterName];
            }

        }

        //Character Selection Back Button Click Event
        private void btnBack1_Click(object sender, EventArgs e)
        {

            //Close this form and make the Welcome Panel visible
            //on the parent form.
            this.Close();
            m_parent.frmclose();
        }

        //Character Selection Accept Button Click Event
        private void btnCharacterAccept_Click(object sender, EventArgs e)
        {

            //Set the Character Selection Panel to invisible
            //and the Character View panel to visible.
            pnlCharacters.Visible = false;
            pnlCharacters2.Visible = true;

            //Display the character name.
            lblName2.Text = m_strCharacterName[bytCharacterName];

            //Display the character gender.
            if (m_bytCharacterGender[bytCharacterName] == 1)
            {
                lblGender.Text = "Male";
            }
            else
            {
                lblGender.Text = "Female";
            }

            //Display the character class and skills.
            switch (m_bytCharacterClass[bytCharacterName])
            {
                case 1:
                    lblClass.Text = "Child of Ares";
                    lblSkill1.Text = "             Bow:";
                    lblSkill2.Text = "2";
                    lblSkill3.Text = "       Dagger:";
                    lblSkill4.Text = "1";
                    lblSkill5.Text = "Dory Spear:";
                    lblSkill6.Text = "3";
                    lblSkill7.Text = "        Javelin:";
                    lblSkill8.Text = "2";
                    lblSkill9.Text = "Light Spear:";
                    lblSkill10.Text = "3";
                    lblSkill11.Text = "Long Spear:";
                    lblSkill12.Text = "3";
                    lblSkill13.Text = "          Shield:";
                    lblSkill14.Text = "3";
                    lblSkill15.Text = " Shortsword:";
                    lblSkill16.Text = "2";
                    lblSkill17.Text = "             Sling:";
                    lblSkill18.Text = "1";
                    lblSkill19.Text = "     Wrestling:";
                    lblSkill20.Text = "1";
                    lblTradeTertiary.Text = "";
                    rtfClassDescription.Text = "Soldiers, warriors, men and women of strength, power, and discipline, "
                    + "war burns through the blood of the Children of Ares.  These heroes "
                    + "are skilled in the use of all weapons, armor, and shields and are the "
                    + "only heroes capable of using heavy shields.  Supplementing their "
                    + "training with weapons are various tactical maneuvers that they "
                    + "have learned in the field of battle such as the Phalanx fighting "
                    + "technique and the shield rush.  The primary statistics of a Child of "
                    + "Ares are Strength, Dexterity, Agility, Constitution, and Willpower.  Faith "
                    + "and Acumen do nothing for these heroes, as they rely more on their "
                    + "instincts, training, and battle hardened senses to carry them through "
                    + "the day.";
                    break;

                case 2:
                    lblClass.Text = "Child of Hermes";
                    lblSkill1.Text = "             Bow:";
                    lblSkill2.Text = "1";
                    lblSkill3.Text = "       Dagger:";
                    lblSkill4.Text = "3";
                    lblSkill5.Text = "        Intrigue:";
                    lblSkill6.Text = "3";
                    lblSkill7.Text = "        Javelin:";
                    lblSkill8.Text = "1";
                    lblSkill9.Text = "Light Spear:";
                    lblSkill10.Text = "1";
                    lblSkill11.Text = "Long Spear:";
                    lblSkill12.Text = "1";
                    lblSkill13.Text = "          Shield:";
                    lblSkill14.Text = "1";
                    lblSkill15.Text = " Shortsword:";
                    lblSkill16.Text = "2";
                    lblSkill17.Text = "             Sling:";
                    lblSkill18.Text = "3";
                    lblSkill19.Text = "     Wrestling:";
                    lblSkill20.Text = "2";
                    lblTradeTertiary.Text = "";
                    rtfClassDescription.Text = "A thief in the night, an assassin in the shadows, a spy behind enemy "
                    + "lines, these are the traits that make up the Children of Hermes. "
                    + "Possessing a keen wit and sharp blade, these heroes are frail but "
                    + "deadly.  They are learned in many abilities of subterfuge and "
                    + "assassination and are skilled in the use of various drugs and poisons. "
                    + "Their primary statistics are Strength, Dexterity, Acumen, Willpower, "
                    + "and Charisma.  Faith does nothing for them, and Agility and "
                    + "Constitution, while not useless, are overridden by this hero's ability to "
                    + "hide in the shadows.  They favor weapons that are light weight and "
                    + "easily concealed, such as the sling and the dagger.";
                    break;

                case 3:
                    lblClass.Text = "Child of Apollo";
                    lblSkill1.Text = "             Bow:";
                    lblSkill2.Text = "3";
                    lblSkill3.Text = "       Dagger:";
                    lblSkill4.Text = "1";
                    lblSkill5.Text = "        Javelin:";
                    lblSkill6.Text = "1";
                    lblSkill7.Text = "Light Spear:";
                    lblSkill8.Text = "2";
                    lblSkill9.Text = "Long Spear:";
                    lblSkill10.Text = "1";
                    lblSkill11.Text = "          Prayer:";
                    lblSkill12.Text = "3";
                    lblSkill13.Text = "          Shield:";
                    lblSkill14.Text = "2";
                    lblSkill15.Text = " Shortsword:";
                    lblSkill16.Text = "1";
                    lblSkill17.Text = "             Sling:";
                    lblSkill18.Text = "1";
                    lblSkill19.Text = "     Wrestling:";
                    lblSkill20.Text = "3";
                    lblTradeTertiary.Text = "Omens";
                    rtfClassDescription.Text = "The Children of Apollo are a closed, monastic group who make up "
                    + "the clergy of the Cult of Apollo.  Skilled in the art of healing and gifted "
                    + "with the Second Sight, only a member from this Order may become an "
                    + "Oracle, a position revered by all of Greece.  In touch with their deity, "
                    + "these heroes favor the bow and are possessing of athleticism as well "
                    + "as great faith.  Their primary statistics are Strength, Dexterity, Faith, "
                    + "Willpower, and Charisma.  Acumen is of little use to them as they look "
                    + "to their deity for the secrets of the universe.  Agility and Constitution are "
                    + "of less use as well, since many of their prayers will compensate for a "
                    + "lack in these disciplines.";
                    break;
            }

            //Display the character stats and Trade Skills.
            lblStrength.Text = Convert.ToString(m_bytCharacterStrength[bytCharacterName]);
            lblDexterity.Text = Convert.ToString(m_bytCharacterDexterity[bytCharacterName]);
            lblAgility.Text = Convert.ToString(m_bytCharacterAgility[bytCharacterName]);
            lblConstitution.Text = Convert.ToString(m_bytCharacterConstitution[bytCharacterName]);
            lblAcumen.Text = Convert.ToString(m_bytCharacterAcumen[bytCharacterName]);
            lblFaith.Text = Convert.ToString(m_bytCharacterFaith[bytCharacterName]);
            lblWillpower.Text = Convert.ToString(m_bytCharacterWillpower[bytCharacterName]);
            lblCharisma.Text = Convert.ToString(m_bytCharacterCharisma[bytCharacterName]);
            lblTradePrimary.Text = m_strCharacterPrimaryTrade[bytCharacterName];
            lblTradeSecondary.Text = m_strCharacterSecondaryTrade[bytCharacterName];
        }

        //Character View Back Button Click Event
        private void btnCreationBack_Click(object sender, EventArgs e)
        {

            //Set the Character View panel to invisible
            //and the Character Selection panel to visible.
            pnlCharacters2.Visible = false;
            pnlCharacters.Visible = true;
        }

    }
}
